<template>
<div style="display:flex;">
  <div id="model">
    <img src="@/assets/cloth/model.png" alt="">
    <div class="tf"><img src="@/assets/cloth/头发1.png" alt="" style="width: 150px;height: 159px;"></div>
    <div class="sy"><img src="@/assets/cloth/上衣1.png" alt="" style="width: 156px;height: 217px;"></div>
  </div>
  <div id="robe">
    <ul>
      <li class="active"><img src="@/assets/cloth/头发.png" alt=""></li>
      <li><img src="@/assets/cloth/上衣.png" alt=""></li>
    </ul>
    <ol>
      <li class="active">
        <div class="tf"><img src="@/assets/cloth/头发2.png" alt="" style="width: 150px;height: 159px;"></div>
        <div class="tf"><img src="@/assets/cloth/头发3.png" alt="" style="width: 150px;height: 159px;"></div>
        <div class="tf"><img src="@/assets/cloth/头发4.png" alt="" style="width: 150px;height: 159px;"></div>
      </li>
      <li>
        <div class="sy"><img src="@/assets/cloth/上衣2.png" alt="" style="width: 156px;height: 217px;"></div>
        <div class="sy"><img src="@/assets/cloth/上衣3.png" alt="" style="width: 156px;height: 217px;"></div>
        <div class="sy"><img src="@/assets/cloth/上衣4.png" alt="" style="width: 156px;height: 217px;"></div>
      </li>
    </ol>
  </div>
</div>
</template>

<script>
export default {
  mounted() {
    let yfObj=document.querySelectorAll("#robe div")
    yfObj.forEach(function(item){
      item.onclick=function(){
        let zd=item.className
        let modelObj=document.querySelector(`#model .${zd}`)
        let temp=item.innerHTML
        item.innerHTML=modelObj.innerHTML
        modelObj.innerHTML=temp
      }
    })

    let ulli = document.querySelectorAll("ul li")
    let olli = document.querySelectorAll("ol li")
    ulli.forEach(function(item,index){
      item.onclick=function(){
        console.log(index-2)
        document.querySelector("ul li.active").removeAttribute("class")
        document.querySelector("ol li.active").removeAttribute("class")
        this.setAttribute("class","active")
        if(olli[index-2]){
          olli[index-2].setAttribute("class","active")
          olli.forEach(function(item) {
            item.style.visibility = "hidden";
          });
          olli[index-2].style.visibility="visible"
        }
      }
    })
  }
}
</script>


<style>
#model{
  height: 600px;
  width: 300px;
  margin-left: 200px;
  position: relative;
}
#model img{
  height: 600px;
}
#model div{
  position: absolute;
}
#model div:nth-of-type(1){
  top: -14px;
  left: -3px;
}
#model div:nth-of-type(2){
  top: 81px;
  left: 4px;
  z-index: 2;
}
#model div:nth-of-type(3){
  top: 202px;
  left: 17px;
}
#model div:nth-of-type(4){
  top: 356px;
  left: -4px;
  z-index: 2;
}
#model div:nth-of-type(5){
  position:absolute;
  top: 496px;
  left: -14px;
  z-index: 2;
}
#robe{
  height: 90%;
  width: 80%;
  margin-right: 20px;
  position: relative;
  display: flex;
  flex-direction: column;
}
#robe > ul {
  display: flex;
}
#robe > ul > li {
  background-color: rgba(255,255,255,0);
  opacity: .6;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;}
#robe > ul > li.active {
  background-color: rgba(255,255,255,0);
  opacity: 1;

}
#robe > ul > li img {
  height:100px;
  width: 200px;
}
#robe > ol {
  flex: 1;
  position: relative;
}
#robe > ol > li {
  width: 100%;
  height: 100%;
  background-color: rgba(255,255,255,.3);
  visibility: hidden;
  display: flex;
  position: absolute;
  flex-wrap: wrap;
}
#robe > ol > li.active {
  visibility: visible;
}
</style>
